package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.rightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class rightsServiceImpl implements rightsService {
    @Autowired
    private rightsMapper rightsMapper;

    /**
     * 1.查询一级列表信息  条件parent_id = 0
     * 2.查询一级目录下的二级列表信息  条件parent_id = 1级ID
     *
     * @return
     */
    @Override
    public List<Rights> findAll() {
        //1级查询
        QueryWrapper<Rights> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id", 0);
        List<Rights> result = rightsMapper.selectList(wrapper);
        //二级查询
        for (Rights ri : result) {
            wrapper.clear();//清空条件构造器
            wrapper.eq("parent_id",ri.getId());
            ri.setChildren(rightsMapper.selectList(wrapper));
        }
        return result;
    }
}
